package com.example.materialviewpagerdemo;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.materialviewpagerdemo.bean.ListViewModel;
import com.example.materialviewpagerdemo.view.OnItemClickListener;
import com.example.materialviewpagerdemo.view.RecyclerViewHolder;

import java.util.List;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.V;

public class RecyclerViewPagerAdapter extends RecyclerView.Adapter<RecyclerViewHolder>{
    List<ListViewModel> contents;
    private OnItemClickListener mClickListener;
    public RecyclerViewPagerAdapter(Context context,List<ListViewModel> contents) {
        this.contents = contents;
    }
    @Override
    public int getItemCount() {
        return contents.size();
    }

    @Override
    public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = null;
        view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.listcontent, parent, false);
        return new RecyclerViewHolder(view,mClickListener);
    }


    @Override
    public void onBindViewHolder(RecyclerViewHolder holder, int position) {
        holder.itemImg.setImageResource(contents.get(position).getImgId());
        holder.itemName.setText(contents.get(position).getDataName());
        try {
            holder.itemData.setText(contents.get(position).getDataContent());
        }catch (NullPointerException e){
            holder.itemData.setText(" ");
        }

        Log.i("nnnn", "onBindViewHolder: "+position);
    }
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.mClickListener = listener;
        System.out.println("listener1");
    }
}
